Conditions | 1 |
Paths | 1 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | 'use strict' |
||
6 | constructor (secret) { |
||
7 | this.cipher = undefined |
||
8 | this.decipher = undefined |
||
9 | |||
10 | this.encrypt = function (text) { |
||
11 | let crypted = this.cipher.update(text, 'utf8', 'hex') |
||
12 | crypted += this.cipher.final('hex') |
||
13 | return crypted |
||
14 | } |
||
15 | |||
16 | this.decrypt = function (text) { |
||
17 | let dec = this.decipher.update(text, 'hex', 'utf8') |
||
18 | dec += this.decipher.final('utf8') |
||
19 | return dec |
||
20 | } |
||
21 | |||
22 | this.match = function (token, text) { |
||
23 | return this.decrypt(token) === text |
||
24 | } |
||
25 | |||
26 | this.cipher = crypto.createCipher('aes-256-cbc', secret) |
||
27 | this.decipher = crypto.createDecipher('aes-256-cbc', secret) |
||
28 | } |
||
29 | } |
||
34 |